package com.fasteat.menu.config;

import com.baidu.aip.contentcensor.AipContentCensor;
import com.baidu.aip.nlp.AipNlp;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author run
 * @since 2021/1/23 10:41
 */
@Configuration
public class BaiduConfig {

    //设置APPID/AK/SK
    @Value("${baidu.aipContentCensor.app-id}")
    public String CENSOR_APP_ID;
    @Value("${baidu.aipContentCensor.api-key}")
    public  String CENSOR_API_KEY;
    @Value("${baidu.aipContentCensor.secret-key}")
    public String CENSOR_SECRET_KEY;

    @Value("${baidu.lexer.app-id}")
    public String LEXER_APP_ID;
    @Value("${baidu.lexer.api-key}")
    public  String LEXER_API_KEY;
    @Value("${baidu.lexer.secret-key}")
    public String LEXER_SECRET_KEY;


    @Bean(name = "censor")
    public AipContentCensor aipContentCensor(){
        // 初始化一个AipContentCensor
        AipContentCensor client = new AipContentCensor(CENSOR_APP_ID, CENSOR_API_KEY, CENSOR_SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        return client;
    }

    @Bean(name = "lexer")
    public AipNlp aipNlp(){
        // 初始化一个AipNlp
        AipNlp client = new AipNlp(LEXER_APP_ID, LEXER_API_KEY, LEXER_SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        return client;
    }

}
